<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>登录页面 -药品生产变更管理平台</title>
<link rel="icon" href="<%=path%>/images/favicon.ico" type="image/ico">
<meta name="author" content="guowenjie">
<link href="<%=path%>/css/bootstrap.min.css" rel="stylesheet">
<link href="<%=path%>/css/materialdesignicons.min.css" rel="stylesheet">
<link href="<%=path%>/css/style.min.css" rel="stylesheet">
<link rel="stylesheet" href="<%=path%>/js/ion-rangeslider/ion.rangeSlider.min.css">
<link href="<%=path%>/js/jconfirm/jquery-confirm.min.css" rel="stylesheet">
<link href="<%=path%>/js/bootstrap-datepicker/bootstrap-datepicker3.min.css" rel="stylesheet">
<link href="<%=path%>/js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link href="<%=path%>/css/materialdesignicons.min.css" rel="stylesheet">
<script type="text/javascript" src="<%=path%>/js/jquery.min.js"></script>
 <script type="text/javascript" src="<%=path%>/js/main.min.js"></script>
<script src="<%=path%>/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="<%=path%>/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/jconfirm/jquery-confirm.min.js"></script>

</head>
 <div class="container-fluid p-t-15">
    
        <div  class="card">
      <div class="card-body">
        <div class="row">
        
         
        
          <div class="col-md-12">
          <div id="toolbar" class="toolbar-btn-action">
            <button id="btn_add" type="button" class="btn btn-primary m-r-5" data-toggle="modal" data-target="#add" >
              <span class="mdi mdi-plus" aria-hidden="true"></span>新增
            </button>
            <button id="btn_edit" type="button" class="btn btn-success m-r-5" onclick="qy()">
              <span class="mdi mdi-check" aria-hidden="true"></span>启用
            </button>
            <button id="btn_edit" type="button" class="btn btn-warning m-r-5" onclick="jy()">
              <span class="mdi mdi-block-helper" aria-hidden="true"></span>禁用
            </button>
            <button id="btn_delete" type="button" class="btn btn-danger"  onclick="del()">
              <span class="mdi mdi-window-close" aria-hidden="true"></span>删除
            </button>
          </div>
           <table id="tb_hhhtxx" ></table>
        </div>
         
            
        </div>
        
      </div></div></div>
      <div class="modal fade " tabindex="-1" id="add" role="dialog" >
            <div class="modal-dialog " role="document" >
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title" id="exampleModalLabel">新增</h4>
                </div>
                <div class="modal-body">
                 
                <form class="form-horizontal"  enctype="multipart/form-data" onsubmit="return toVaild();">
                <div class="form-group">
              <label class="col-xs-12" for="Username">姓名</label>
              <div class="col-xs-12">
                <input class="form-control" type="text" id="Username" name="user.Username" placeholder="姓名..">
              </div>
            </div>
            <div class="form-group">
              <label class="col-xs-12" for="Usercode">账号</label>
              <div class="col-xs-12">
                <input class="form-control" type="text" id="Usercode" name="user.Usercode" placeholder="账号..">
              </div>
            </div>
         <!--    <div class="form-group">
              <label class="col-xs-12" for="Password">密码</label>
              <div class="col-xs-12">
                <input class="form-control" type="password" id="Password" name="user.Password" placeholder="密码..">
              </div>
            </div> -->
            <div class="form-group">
              <label class="col-xs-12" for="Roleid">角色</label>
              <div class="col-xs-12">
                <select class="form-control" id="Roleid" name="user.Roleid" size="1">
                  <option value="3" selected >普通人员</option>
                  <option value="4">数据维护员</option>
                  <option value="2">系统管理员</option>
                </select>
              </div>
            </div>
            
            <div class="form-group">
              <div class="col-xs-12">
                <button class="btn btn-primary" type="submit">提交</button><label id="ts" Style="color:red;padding-left: 38px"></label>
              </div>
            </div>
                </form>
               
                 
                </div>
                
              </div>
            </div>
          </div>
       <script type="text/javascript">
       
      
       
       $('#tb_hhhtxx').bootstrapTable({
   		classes: 'table table-condensed table-hover',
   		 url:'<%=path%>/admin/showusers',
   		method: 'post',
   	     dataType : 'json',        // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
   	  uniqueId: 'Userid',
      idField: 'Userid',             // 每行的唯一标识字段
      toolbar: '#toolbar',       // 工具按钮容器
      //clickToSelect: true,     // 是否启用点击选中行
      showRefresh: true,         // 是否显示刷新按钮
      
      //showToggle: true,        // 是否显示详细视图和列表视图的切换按钮(clickToSelect同时设置为true时点击会报错)
    
      pagination: true,                    // 是否显示分页
      sortOrder: "asc",                    // 排序方式
      queryParams: function(params) {
          var temp = {
              limit: params.limit,         // 每页数据量
              offset: params.offset,       // sql语句起始索引
              page: (params.offset / params.limit) + 1,
              sort: params.sort,           // 排序的列名
              sortOrder: params.order      // 排序方式'asc' 'desc'
          };
          return temp;
      },                                   // 传递参数
      sidePagination: "client",            // 分页方式：client客户端分页，server服务端分页
      pageNumber: 1,                       // 初始化加载第一页，默认第一页
      pageSize: 10,                        // 每页的记录行数
      pageList: [10, 25, 50, 100],         // 可供选择的每页的行数
      search: true,                      // 是否显示表格搜索，此搜索是客户端搜索
      
      //showExport: true,        // 是否显示导出按钮, 导出功能需要导出插件支持(tableexport.min.js)
      //exportDataType: "basic", // 导出数据类型, 'basic':当前页, 'all':所有数据, 'selected':选中的数据
    
       columns: 
   		    	[{
   		         checkbox: true    // 是否显示复选框
   		     },{field: 'Usercode',title:'账号'},
   		       {field: 'Password',title:'密码',
   		    		formatter: function (value, row, index) {	
   		    			var result = "<button class='btn btn-sm btn-purple' onclick='czpw("+row.Userid+")'>重置密码</button>"; 
   		    			return result;
   		    		}},
   		    		{field: 'Username',title:'姓名'},
   		    		{field: 'Forbidden',title:'状态',
   	   		    		formatter: function (value, row, index) {	
   	   		    		 var result = "";  
   	   		    		 if(value == 0){
   	   		    		result = "<button class='btn btn-sm btn-success'>正常</button>";
   	   		    		
   	   		    		 }else{
   	   		    		result = "<button class='btn btn-sm btn-warning'>禁用</button>";	 
   	   		    		 }
   	   		    		 
   	   		    	    return result;     
   	   		    		}	
   		    		},
   		    		{field: 'Rolename',title:'角色'},
   		    	     ],
   		    	  onClickCell: function(field, value, row, $element) {
   		    		
   		    	  },
   		             onLoadSuccess: function(data){
   		     	        $("[data-toggle='tooltip']").tooltip();
   		     	    
   		     	        
   		     	    
   		     	    }
   		});
     
       function toVaild(){
    	  
    	   let Username = $('#Username').val();
    	   let Usercode = $('#Usercode').val();
    	   let roleid = $('#Roleid').val();
     	  if(Username=="" || Usercode=="" ){
    		   $('#ts').html("姓名与账号不得为空！");
    		
    	   }else{
    		   
    		   $.ajax({
    	   			 type: "post",//方法类型
    	   		    dataType: "json",//预期服务器返回的数据类型 jsonp跨域
    	   			url: "<%=path%>/admin/newuser",
    	   			 data:{
    	   				"username":Username,
    	   				"usercode":Usercode,
    	   				"RoleID":roleid
    	   			}, 
    	   			success: function(req) {
    	   		
    	   		    if(req.code == 0){
    	   		    	$('#add').modal('hide');
       	   			    $.alert({
                	        title: '提示',
                	        content: '操作成功，账号为：'+Usercode+'  密码为'+req.msg,
                			buttons: {
                				confirm: {
                					text: '确认',
                					btnClass: 'btn-primary',
                					action: function(){
                						$('#tb_hhhtxx').bootstrapTable('refresh');   
                					}
                				}
                			}
                	    });
       	   			    
       	   			  }else{
    	   		    	$('#ts').html(req.msg);		
    	   		    	
    	   		    }		
    	   		
    	   		  
    	   				 
    	   			},error: function(e){ 
    	   			 console.log(e.responseText);	
    	   			 $('#ts').html("保存失败，数据异常！");	
    	   			 
    	   			}
    	   		});
    		}
     	 return false;
    	 }
       
       
       function qy(){
       
    	let row=$("#tb_hhhtxx").bootstrapTable('getSelections');   
    	if(row.length==0){
    		$.alert({
    	        title: '提示',
    	        content: "请选择要操作的数据"})
    	}else{
    	    let userids = new Array();
    		for(var a=0;a<row.length;a++){
    			userids.push(row[a].Userid);			
    		}
    		changeuserForbidden(userids.join(","),0)
    		
    	} 
    	
       }
       
       function jy(){
    	   let row=$("#tb_hhhtxx").bootstrapTable('getSelections');     
    	   if(row.length==0){
    		   $.alert({
    	        title: '提示',
    	        content: "请选择要操作的数据"})
       	    }else{
       	    	let userids = new Array();
        		for(var a=0;a<row.length;a++){
        			userids.push(row[a].Userid);	
        		}
        		changeuserForbidden(userids.join(","),1)
       	    }
       }
       
       function del(){
    	   let row=$("#tb_hhhtxx").bootstrapTable('getSelections');     
    	   if(row.length==0){
    		   $.alert({
    	        title: '提示',
    	        content: "请选择要操作的数据"})
       	    }else{
       	    	let userids = new Array();
        		for(var a=0;a<row.length;a++){
        			if(row[a].Forbidden == 1){
        				userids.push(row[a].Userid);	
        			}else{
        				$.alert({
        	    	        title: '提示',
        	    	        content: "只能删除已停用的账号"})
        	    	        return;
        			}
        		}
        		changeuserForbidden(userids.join(","),99)
        		
        		
       	    }
       }
       
       
       function changeuserForbidden(userids,Forbidden){
    	   
    	   $.ajax({
	   			 type: "post",//方法类型
	   		    dataType: "json",//预期服务器返回的数据类型 jsonp跨域
	   			url: "<%=path%>/admin/changeuserForbidden",
	   			 data:{
	   				"userids":userids,
	   				"Forbi":Forbidden
	   			}, 
	   			success: function(req) {
	   		    $.alert({
          	        title: '提示',
          	        content: '操作成功',
          			buttons: {
          				confirm: {
          					text: '确认',
          					btnClass: 'btn-primary',
          					action: function(){
          						$('#tb_hhhtxx').bootstrapTable('refresh');   
          					}
          				}
          			}
          	    });
 	   				 
	   			},error: function(e){ 
	   			 console.log(e.responseText);	
	   			}
	   		});   
    	   
    	   
       }
       
       
       function czpw(Userid){
    	  
    	   $.ajax({
	   			 type: "post",//方法类型
	   		    dataType: "json",//预期服务器返回的数据类型 jsonp跨域
	   			url: "<%=path%>/admin/czpw",
	   			 data:{
	   				"UserId":Userid
	   			}, 
	   			success: function(req) {
	   		    $.alert({
        	        title: '提示',
        	        content: '操作成功,新密码为:'+req.msg,
        			buttons: {
        				confirm: {
        					text: '确认',
        					btnClass: 'btn-primary',
        					action: function(){
        						$('#tb_hhhtxx').bootstrapTable('refresh');   
        					}
        				}
        			}
        	    });
	   				 
	   			},error: function(e){ 
	   			 console.log(e.responseText);	
	   			}
	   		});   
       }
       
      </script>
       </body>

</html>   